package eu.robico.simulator.simulatorinterface;

import java.util.Observable;

import eu.robico.simulator.simulatorinterface.communication.Protocol.SimulationStatus;

public class SimulatorStatus extends Observable
{
	public enum SimulatorStatusUpdate
	{
		SIMULATORSTATUSUPDATE,
		CONNECTIONSTATUSUPDATE,
		CONNECTIONSTATEUPDATE,
		IPUPDATE,
		PORTUPDATE
	}
	
	public enum ConnectionState
	{
		DISCONNECTED,
		CONNECTED,
		ERROR
	}
	
	private String ip, connectionStatus;
	private short port;
	private ConnectionState connectionState;
	private SimulationStatus simulationStatus;

	public static SimulatorStatus copyOf(SimulatorStatus original)
	{
		SimulatorStatus copy = new SimulatorStatus();
		if (original.ip != null)
			copy.ip = original.ip;
		if (original.connectionStatus != null)
			copy.connectionStatus = original.connectionStatus;
		copy.port = original.port;
		copy.connectionState = original.connectionState;
		copy.simulationStatus = original.simulationStatus;
		return copy;
	}
	
	//Getters
	public SimulationStatus getSimulatorStatus() { return simulationStatus; }
	public String getConnectionStatus() { return connectionStatus; }
	public String getIp() { return ip; }
	public short getPort() { return port; }
	public ConnectionState getConnectionState() { return connectionState; }
	
	//Setters
	public void setSimulatorStatus(SimulationStatus simulationStatus) 
	{ 
		this.simulationStatus = simulationStatus;
		setChanged();
		notifyObservers(SimulatorStatusUpdate.SIMULATORSTATUSUPDATE);
	}
	public void setConnectionStatus(String connectionStatus) 
	{ 
		this.connectionStatus = connectionStatus;
		setChanged();
		notifyObservers(SimulatorStatusUpdate.CONNECTIONSTATUSUPDATE);
	}
	
	public void setIp(String ip) 
	{ 
		this.ip = ip;
		setChanged();
		notifyObservers(SimulatorStatusUpdate.IPUPDATE);
	
	}
	public void setPort(short port) 
	{ 
		this.port = port;
		setChanged();
		notifyObservers(SimulatorStatusUpdate.PORTUPDATE);
	}
	
	public void setConnectionState(ConnectionState connectionState) 
	{ 
		this.connectionState = connectionState;
		setChanged();
		notifyObservers(SimulatorStatusUpdate.CONNECTIONSTATEUPDATE);
	}
	
	//Tests
	public boolean hasIp() { return ip != null; }
	public boolean hasConnectionStatus() {return connectionStatus != null; }
	public boolean isConnected() { return connectionState == ConnectionState.CONNECTED; }
}
